﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.ChangeEntityRotation, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_ChangeEntityRotation : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.ChangeEntityRotation;

        public override string name => LevelEditorConst.ChangeEntityRotation;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [InspectorName("y轴旋转值")] public int rotationY;
        [InspectorName("是否是增量")] public bool isIncrement;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_ChangeEntityRotation()
            {
                // tagOrMcid = this.tagOrMcid,
                rotationY = this.rotationY,
                isIncrement = this.isIncrement
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }
        
        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_ChangeEntityRotation rNode)
            {
                this.rotationY = rNode.rotationY;
                this.isIncrement = rNode.isIncrement;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_ChangeEntityRotation rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}